package controller.worker;

import entity.User;
import util.JdbcDeal;

import javax.swing.*;
import java.sql.SQLException;

public class Worker_del extends JPanel {

    public Worker_del(User user) {
        if(user.isFlag()==false){
            JOptionPane.showMessageDialog(this, "没有权限！","", JOptionPane.WARNING_MESSAGE);
            return;
        }
        String table_wno = JOptionPane.showInputDialog("请输入要删除员工工号）");
        String sql = "DELETE FROM worker WHERE Wno = '" + table_wno + "'";
        JdbcDeal jdbcDeal = new JdbcDeal();
        try {
            if(jdbcDeal.del(sql) == 1){
                JOptionPane.showMessageDialog(this, "成功删除一条记录！","",JOptionPane.PLAIN_MESSAGE);
                return;
            } else {
                JOptionPane.showMessageDialog(this, "删除记录失败！","", JOptionPane.WARNING_MESSAGE);
                return;
            }
        } catch (SQLException throwables) {
            JOptionPane.showMessageDialog(this, "删除记录失败！可能和其他信息有联动！请先删除相关信息！","", JOptionPane.WARNING_MESSAGE);
            throwables.printStackTrace();
        }
    }
}
